// pages/newpeople/newpeople.js
var o,page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    is_new_user: true,
    msgList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    o = this
    page = 1
    o.user_status()
    o.text_new_user()
    o.user_free_goods()
  },
  user_free_goods:function(e){
    var list = o.data.list
    getApp().request({
      url: getApp().api.default.user_free_goods,
      data:{
        page:page
      },
      success: function (e) {
        if (e.code == 0) {
          for (var i = 0; i < e.data.list.length; i++) {
            list.push(e.data.list[i])
          }
          o.setData({
            list: list
          })
        }
        // 0 == e.code && 
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  },
  text_new_user: function () {
    getApp().request({
      url: getApp().api.default.text_new_user,
      success: function (e) {
        if (e.code == 0) {
          o.setData({
            msgList: e.data.list
          })
        }
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  },
  goods: function (e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/goods/goods?id=' + id + '&xr=1',
    })
  },
  user_status: function (e) {
    o = this
    getApp().request({
      url: getApp().api.default.user_status,
      success: function (e) {
        if (e.data.is_new_user) {
          console.log('123132')
        }
        o.setData({
          is_new_user: e.data.is_new_user
        })
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  },
  gos: function (e) {
    wx.navigateTo({
      url: '/pages/Nineactivities/Nineactivities',
    })
  },
  guanb:function(e){
    o.setData({
      is_new_user: true
    })
  },
    /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('123')
    page += 1
    o.user_free_goods()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})